﻿<controls:ChildWindow xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"  
                      x:Class="IndexMarkSilverlightClient.Views.RespAnswersWindow"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls" 
           xmlns:viewmodel="clr-namespace:IndexMarkSilverlightClient.Views"   
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:classes="clr-namespace:IndexMarkSilverlightClient.Classes"
           xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"                      
           xmlns:IndexMarkSilverlightClient="clr-namespace:IndexMarkSilverlightClient"
           xmlns:converters="clr-namespace:IndexMarkSilverlightClient.Classes.Converters" 
           xmlns:sharedcontrols="clr-namespace:SharedCode.Controls;assembly=SharedCode" 
                      xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
           Width="600" Height="400" 
           Title="RespAnswersWindow">
    
    <controls:ChildWindow.Resources>
        
        <viewmodel:RespAnswersViewModel x:Key="RespAnswersViewModel"/>
        <converters:BoolToHeadersVisibilityConverter x:Key="BoolToHeadersVisibilityConverter"/>

        <Style TargetType="Button" x:Key="ActionButtonStyle">
            <Setter Property="Margin" Value="3"/>
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>

        <Style TargetType="dataprimitives:DataGridColumnHeader" x:Key="CheckBoxHeaderStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca">
                            <Grid>
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                        <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                        <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                        <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                        <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                        <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                        <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                                <CheckBox ToolTipService.ToolTip="Отметить все" x:Name="commonCheckBox" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Checked="commonCheckBox_Checked" Unchecked="commonCheckBox_Unchecked"/>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="dataprimitives:DataGridColumnHeader" x:Key="LowHeaderStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca" Height="20">
                            <Grid>
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                        <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                        <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                        <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                        <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                        <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                        <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                                <TextBlock Text="{TemplateBinding Content}" Margin="5, 0, 5, 0"/>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Height" Value="22"/>
        </Style>

    </controls:ChildWindow.Resources>

    <Grid x:Name="LayoutRoot" Margin="2" x:Uid="1" Background="{StaticResource ContentPanelBackgroundColorBrush2}">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" Height="40" VerticalAlignment="Center" x:Name="ButtonPanel">
            <Button x:Name="Add" Click="Add_Click" ToolTipService.ToolTip="Добавить показатель" Style="{StaticResource ActionButtonStyle}">
                <Image Source="/IndexMarkSilverlightClient;component/Views/Resources/Actions/Add_16.png"/>
                <interactivity:Interaction.Behaviors>
                    <classes:ButtonBehavior/>
                </interactivity:Interaction.Behaviors>
            </Button>

            <Button x:Name="Update" Style="{StaticResource ActionButtonStyle}" Click="Update_Click" ToolTipService.ToolTip="Редактировать показатель" IsEnabled="{Binding IsHasEdit, Source={StaticResource RespAnswersViewModel}}">
                <Image Source="/IndexMarkSilverlightClient;component/Views/Resources/Actions/Modify_16.png"/>
                <interactivity:Interaction.Behaviors>
                    <classes:ButtonBehavior/>
                </interactivity:Interaction.Behaviors>
            </Button>

            <Button x:Name="Delete" Style="{StaticResource ActionButtonStyle}" Click="Delete_Click" ToolTipService.ToolTip="Удалить показатель\градацию" IsEnabled="{Binding IsHasDelete, Source={StaticResource RespAnswersViewModel}}">
                <Image Source="/IndexMarkSilverlightClient;component/Views/Resources/Actions/Delete_16.png"/>
                <interactivity:Interaction.Behaviors>
                    <classes:ButtonBehavior/>
                </interactivity:Interaction.Behaviors>
            </Button>
                
            <StackPanel Orientation="Horizontal">
                <TextBlock Margin="5, 0, 0, 0" Height="40" Name="textBlock1" TextWrapping="Wrap" FontSize="12" Text="Показатель: " VerticalAlignment="Center" FontWeight="Bold"/>
                <TextBlock Name="textBlock2" TextWrapping="Wrap" FontSize="12" Text="{Binding CurrentChar.Name, Source={StaticResource RespAnswersViewModel}}" VerticalAlignment="Top" ToolTipService.ToolTip="{Binding CurrentChar.Name}" Width="390" />
            </StackPanel>
        </StackPanel>

        <sharedcontrols:LoadingBar VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed" Action="сохранение" x:Name="loadBar" Grid.RowSpan="3"/>
        
        <data:DataGrid x:Name="VolumeTable" ItemsSource="{Binding RespAnswers.Answers, Source={StaticResource RespAnswersViewModel}}"  
             AutoGenerateColumns="False" Height="290" Background="Transparent" SelectionMode="Single" LoadingRow="VolumeTable_LoadingRow" 
             RowStyle="{StaticResource StandartNotSelectedDataGridRowStyle}" CellStyle="{StaticResource NotSelectedDataGridCellStyle}" 
             BorderBrush="CadetBlue" BorderThickness="1" KeyDown="VolumeTable_KeyDown" Grid.Row="1">
                <data:DataGrid.Columns>

                    <data:DataGridTemplateColumn HeaderStyle="{StaticResource CheckBoxHeaderStyle}" >
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsSelected}" ToolTipService.ToolTip="Выделить для редактирования/удаления" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>

                    <data:DataGridTextColumn Width="40" Header="№" Binding="{Binding Order, Mode=TwoWay}"/>
                        
                    <data:DataGridTemplateColumn Header="Градация" Width="330" IsReadOnly="True">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <data:DataGrid Width="329" GridLinesVisibility="None" Background="Transparent" HorizontalScrollBarVisibility="Hidden" 
                                                HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent" BorderThickness="0" BorderBrush="Transparent" 
                                                ItemsSource="{Binding Gradations}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" AutoGenerateColumns="False" 
                                                RowStyle="{StaticResource StandartNotSelectedDataGridRowStyle}" CellStyle="{StaticResource NotSelectedDataGridCellStyle}" HeadersVisibility="{Binding IsGraduated, Source={StaticResource RespAnswersViewModel}, Converter={StaticResource BoolToHeadersVisibilityConverter}}">
                                    <data:DataGrid.Columns>
                                        <data:DataGridTemplateColumn Width="270" Header="Градация" HeaderStyle="{StaticResource LowHeaderStyle}">
                                            <data:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Name}" ToolTipService.ToolTip="{Binding}" Margin="2"/>
                                                </DataTemplate>
                                            </data:DataGridTemplateColumn.CellTemplate>
                                        </data:DataGridTemplateColumn>
                                        <data:DataGridTextColumn Binding="{Binding Volume}" IsReadOnly="True" Width="58.9" Header="Объем" HeaderStyle="{StaticResource LowHeaderStyle}"/>
                                    </data:DataGrid.Columns>
                                </data:DataGrid>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>

                    <data:DataGridTemplateColumn Header="Объем" Width="100">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="5" Loaded="TextBlock_Loaded" FontWeight="Bold"/>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>

                    <data:DataGridTemplateColumn Header="Ед. изм." Width="75">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding CurrentChar.Unit, Source={StaticResource RespAnswersViewModel}}" Margin="5"/>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>

                </data:DataGrid.Columns>

            </data:DataGrid>
            
            

        <Grid Background="Transparent" VerticalAlignment="Bottom" Height="30" Grid.Row="2">
            <Button x:Name="CancelButton" Content="Отмена" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right"
                    Margin="0,6,0,0" ToolTipService.ToolTip="Отменить изменения"/>
            <Button x:Name="OKButton" Content="ОК" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,6,79,0"
                    ToolTipService.ToolTip="Сохранить изменения" IsEnabled="{Binding IsCorrect, Source={StaticResource RespAnswersViewModel}}"/>
        </Grid>

    </Grid>

</controls:ChildWindow>